package com.qys.livesMall.system.controller.sys;


import com.qys.livesMall.common.result.R;
import com.qys.livesMall.system.model.dto.sys.H2SysShareConfigDTO;
import com.qys.livesMall.system.model.vo.sys.H2SysShareConfigVO;
import com.qys.livesMall.system.service.SysShareConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-05-23
 */
@RestController
@Tag(name = "后台管理-分红配置")
@RequestMapping("/sys/share/config")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysShareConfigController {

    private final SysShareConfigService shareConfigService;

    @GetMapping(value = "/list/{type}")
    @Operation(
            summary = "分红配置列表",
            parameters = {
                    @Parameter(name = "type", description = "类型(0店铺,1个人)")
            }
    )
    public R<List<H2SysShareConfigVO>> list(@PathVariable Byte type) {
        return R.ok(shareConfigService.list(type));
    }

    @Operation(summary = "增加分红配置")
    @PostMapping(value = "/add")
    public R<Void> add(@RequestBody @Validated H2SysShareConfigDTO config) {
        shareConfigService.save(config);
        return R.ok();
    }

    @Operation(summary = "改分红配置")
    @PutMapping(value = "/edit")
    public R<Void> update(@RequestBody @Validated H2SysShareConfigDTO config) {
        shareConfigService.save(config);
        return R.ok();
    }

    @Operation(summary = "删分红配置")
    @DeleteMapping(value = "/del/{id}")
    public R<Void> del(@PathVariable Integer id) {
        shareConfigService.removeById(id);
        return R.ok();
    }
}
